From f85b37e310b2e14d37e04618cc853d1d82079982 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 2 Jan 2022 16:51:03 -0700 Subject: [PATCH] use hierarchy with cmake. (#807) * use hierarchy with cmake. * adjust cmake test script for hierarchy. the default target with cmake builds both the CLI and the GUI. alternatively, "cmake --build . --target gpsbabel" to build just the CLI or "cmake --build . --target GPSBabelFE|gpsbabelfe to build just the GUI. * detect attempts to generate a build system from a subdirectory. * fix shellcheck issues. --- .github/workflows/fedora.yml | 2 +- .github/workflows/ubuntu.yml | 10 ++-- CMakeLists.txt | 11 ++++- GPSBabel.pro | 1 - gbversion.cmake | 6 +-- gui/CMakeLists.txt | 11 ++--- build_and_test => tools/build_and_test.sh | 4 +- ...and_test_cmake => build_and_test_cmake.sh} | 13 ++--- ...build_extra_tests => build_extra_tests.sh} | 0 tools/make_windows_release.ps1 | 49 +++++++++++-------- 10 files changed, 56 insertions(+), 51 deletions(-) rename build_and_test => tools/build_and_test.sh (96%) rename tools/{build_and_test_cmake => build_and_test_cmake.sh} (87%) rename tools/{build_extra_tests => build_extra_tests.sh} (100%) diff --git a/.github/workflows/fedora.yml b/.github/workflows/fedora.yml index b4e517158..41e4d6e04 100644 --- a/.github/workflows/fedora.yml +++ b/.github/workflows/fedora.yml @@ -30,4 +30,4 @@ jobs: - name: build_and_test run: | - ./build_and_test + ./tools/build_and_test.sh diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index b4ecbf5ab..eac0f10bb 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -24,7 +24,7 @@ jobs: - name: build_and_test run: | - ./build_and_test + ./tools/build_and_test.sh cmake: name: cmake Build @@ -40,7 +40,7 @@ jobs: - name: build_and_test run: | - ./tools/build_and_test_cmake + ./tools/build_and_test_cmake.sh qtio_gcc: name: qtio gcc Build @@ -57,7 +57,7 @@ jobs: - name: build_and_test run: | . /opt/qtio.env - ./build_and_test + ./tools/build_and_test.sh qtio_clang: name: qtio clang Build @@ -75,7 +75,7 @@ jobs: - name: build_and_test run: | . /opt/qtio.env - ./build_and_test + ./tools/build_and_test.sh advanced: name: advanced Build @@ -91,7 +91,7 @@ jobs: - name: build_extra_tests run: | - ./tools/build_extra_tests + ./tools/build_extra_tests.sh coverage: name: coverage Build diff --git a/CMakeLists.txt b/CMakeLists.txt index fa6d0dfaf..fce1a63b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,20 @@ cmake_minimum_required(VERSION 3.11) include(gbversion.cmake) -configure_file(gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF) project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION}) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) +# Do this after we set up common variables but before creating other +# variables that will be inherited. +add_subdirectory(gui) + +# FIXME: When we rearrange the project directory structure everything +# below here should be in it's own CMakeList.txt + +configure_file(gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF) + # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Handle the Qt rcc code generator automatically @@ -249,7 +257,6 @@ set(HEADERS gbfile.h gbser.h gbser_private.h - gbversion.h geojson.h ggv_bin.h globalsat_sport.h diff --git a/GPSBabel.pro b/GPSBabel.pro index dfb828529..013604131 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -221,7 +221,6 @@ HEADERS = \ gbfile.h \ gbser.h \ gbser_private.h \ - gbversion.h \ geojson.h \ ggv_bin.h \ globalsat_sport.h \ diff --git a/gbversion.cmake b/gbversion.cmake index 0195e4296..dc6f1a55f 100644 --- a/gbversion.cmake +++ b/gbversion.cmake @@ -1,10 +1,8 @@ # Use GB variable to express ownership intention and avoid conflict with # documented and undocumented cmake variables. -# Until we do a hierarchical build the build directory for gpsbabel and -# the build directory for GPSBabelFE are independent. Only the source -# directories have a known relationship. Including this pri file from the -# source tree will generate the version file in the current build directory. +# Including this pri file from ${CMAKE_SOURCE_DIR} will generate the version +# file in the current build directory, i.e. ${CMAKE_CURRENT_BINARY_DIR}. # Note some of these variables are also used in the gui to generate setup.iss. # Note some of these variables are also used in the cli to generate documents. diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index bc62bc5af..ad42f3b83 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -1,12 +1,9 @@ -cmake_minimum_required(VERSION 3.11) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + message(FATAL_ERROR "Please use CMakeLists.txt in the project root directory to generate a build system.") +endif() -include(../gbversion.cmake) -configure_file(../gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF) +configure_file(${CMAKE_SOURCE_DIR}/gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF) configure_file(setup.iss.in setup.iss @ONLY NEWLINE_STYLE CRLF) -project(gpsbabelfe LANGUAGES CXX VERSION ${GB.VERSION}) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/build_and_test b/tools/build_and_test.sh similarity index 96% rename from build_and_test rename to tools/build_and_test.sh index 6d540e5a3..9993e7bfd 100755 --- a/build_and_test +++ b/tools/build_and_test.sh @@ -14,8 +14,8 @@ fi git --no-pager log -n 1 # build and test keeping output within the pwd. export GBTEMP=$(pwd)/gbtemp -mkdir -p $GBTEMP -qmake WEB=$(pwd)/gpsbabel_docdir +mkdir -p "$GBTEMP" +qmake WEB="$(pwd)/gpsbabel_docdir" # As of 2018-10, all the virtualized travis build images are two cores per: # https://docs.travis-ci.com/user/reference/overview/ # We'll be slightly abusive on CPU knowing that I/O is virtualized. diff --git a/tools/build_and_test_cmake b/tools/build_and_test_cmake.sh similarity index 87% rename from tools/build_and_test_cmake rename to tools/build_and_test_cmake.sh index 717e91d6b..59d49b670 100755 --- a/tools/build_and_test_cmake +++ b/tools/build_and_test_cmake.sh @@ -14,24 +14,19 @@ fi git --no-pager log -n 1 # build and test keeping output within the pwd. export GBTEMP=$(pwd)/gbtemp -mkdir -p $GBTEMP -cmake . -G Ninja -DCMAKE_BUILD_TYPE=Release -DWEB=$(pwd)/gpsbabel_docdir +mkdir -p "$GBTEMP" +cmake . -G Ninja -DCMAKE_BUILD_TYPE=Release -DWEB="$(pwd)/gpsbabel_docdir" # As of 2018-10, all the virtualized travis build images are two cores per: # https://docs.travis-ci.com/user/reference/overview/ # We'll be slightly abusive on CPU knowing that I/O is virtualized. #make toolinfo cmake --build . --target clean -cmake --build . +cmake --build . --target gpsbabel cmake --build . --target gpsbabel.html cmake --build . --target gpsbabel.pdf cmake --build . --target gpsbabel.org cmake --build . --target check -#make -j 3 unix-gui -# FIXME: use hierarchical build -pushd gui -cmake . -G Ninja -cmake --build . -popd +cmake --build . --target gpsbabelfe # test for mangled encoding of command line arguments ./test_encoding_latin1 ./test_encoding_utf8 diff --git a/tools/build_extra_tests b/tools/build_extra_tests.sh similarity index 100% rename from tools/build_extra_tests rename to tools/build_extra_tests.sh diff --git a/tools/make_windows_release.ps1 b/tools/make_windows_release.ps1 index 32e8a0f5f..50ed936b9 100755 --- a/tools/make_windows_release.ps1 +++ b/tools/make_windows_release.ps1 @@ -31,7 +31,11 @@ $ErrorActionPreference = "Stop" Get-Item tools/make_windows_release.ps1 -ErrorAction Stop | Out-Null $gpsbabel_src_dir = "$Pwd" $gpsbabel_build_dir = "$($gpsbabel_src_dir)\..\$($gpsbabel_build_dir_name)" -$gui_build_dir = "$($gpsbabel_src_dir)\$($gui_build_dir_name)" +if ( "$flow" -eq "cmake" ) { + $gui_build_dir = "$($gpsbabel_build_dir)" +} else { + $gui_build_dir = "$($gpsbabel_src_dir)\$($gui_build_dir_name)" +} if ( "$flow" -eq "msbuild" ) { # translate target architecture to Platform property value. switch ($arch) { @@ -71,26 +75,27 @@ if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } # copy GPSBabel.exe for use by test_script Remove-Item "$($gpsbabel_src_dir)\release" -Recurse -ErrorAction Ignore New-Item "$($gpsbabel_src_dir)\release" -type directory -Force | Out-Null -Copy-Item release\GPSBabel.exe "$($gpsbabel_src_dir)\release\GPSBabel.exe" -Set-Location "$($gpsbabel_src_dir)" -# make sure we are staring with a clean build directory -Remove-Item "$($gui_build_dir)" -Recurse -ErrorAction Ignore -New-Item "$($gui_build_dir)" -type directory -Force | Out-Null -Set-Location "$($gui_build_dir)" -switch ($flow) { - "mingw" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-g++" } - "msbuild" { qmake -tp vc "$($gpsbabel_src_dir)\gui\app.pro" } - "nmake" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-msvc" } - "cmake" { cmake -G "Ninja" -DCMAKE_BUILD_TYPE:STRING:="Release" -DCMAKE_PREFIX_PATH:PATH="$($CMAKE_PREFIX_PATH)" -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH="$($gui_build_dir)\release" "$($gpsbabel_src_dir)\gui" } -} -if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } -switch ($flow) { - "mingw" { ming32-make } - "msbuild" { msbuild GPSBabelFE.vcxproj -property:Configuration=Release -property:Platform=$platform } - "nmake" { nmake /NOLOGO } - "cmake" { cmake --build . } +Copy-Item "$($gpsbabel_build_dir)\release\GPSBabel.exe" "$($gpsbabel_src_dir)\release\GPSBabel.exe" +if ( "$flow" -ne "cmake" ) { + Set-Location "$($gpsbabel_src_dir)" + # make sure we are staring with a clean build directory + Remove-Item "$($gui_build_dir)" -Recurse -ErrorAction Ignore + New-Item "$($gui_build_dir)" -type directory -Force | Out-Null + Set-Location "$($gui_build_dir)" + switch ($flow) { + "mingw" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-g++" } + "msbuild" { qmake -tp vc "$($gpsbabel_src_dir)\gui\app.pro" } + "nmake" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-msvc" } + } + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + switch ($flow) { + "mingw" { ming32-make } + "msbuild" { msbuild GPSBabelFE.vcxproj -property:Configuration=Release -property:Platform=$platform } + "nmake" { nmake /NOLOGO } + } + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } } -if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } +Set-Location "$($gui_build_dir)" # work around errors with lupdate, lrelease misprocessing qtHaveModule(webenginewidgets) # and generating a message to stderr WARNING: Project ERROR: Unknown module(s) in QT: webkit webkitwidgets # and, on Windows, setting $? to false. @@ -108,6 +113,10 @@ Copy-Item "$($gui_build_dir)\release\GPSBabelFE.exe" "$($gui_build_dir)\package\ & "$($windeployqt)" --verbose 1 --plugindir package\plugins package\GPSBabelFE.exe package\GPSBabel.exe if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } if ($buildinstaller -eq "true") { + # set location to location of generated setup.iss file. + if ( "$flow" -eq "cmake" ) { + Set-Location "$($gpsbabel_build_dir)/gui" + } & "$($iscc)" /Dpackage_dir="$($gui_build_dir)\package" /Dsource_dir="$($gpsbabel_src_dir)\gui" setup.iss if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } } -- 2.30.2